public class Fraction{
    private int fenzi, fenmu;
    private String out;
    private double value = fenzi * 1.0 / fenmu;
    private boolean illegal = false;
    public Fraction(int fenzi, int fenmu){
        if(fenmu==0){illegal = true;
            return;}
        int gcd = 1;
        int smaller = fenzi > fenmu ? fenmu : fenzi;
        int bigger = fenzi <= fenmu ? fenmu : fenzi;
        gcd = MaxCommonFactor(bigger,smaller);
        this.fenmu = fenmu/gcd;
        this.fenzi = fenzi/gcd;
    }
    public int MaxCommonFactor(int big, int small){
        if(big % small==0)return small;
        else return MaxCommonFactor(small,big % small);
    }
    public int getFenzi(){
        return this.fenzi;
    }
    public int getFenmu(){
        return this.fenmu;
    }
    public double getReal(){
        return this.fenzi * 1.0 / (this.fenmu + 0.0);
    }
    public String toString(){
        if(illegal)return "illegal!";
        String str = this.fenzi + "/" + this.fenmu, str0 = "" + this.fenzi;
        if(this.fenmu == 1)return str0;
        return str;
    }
    public boolean equal(Fraction c){
        if(this.fenmu==c.getFenmu()&&this.fenzi==c.getFenzi())return true;
        return false;
    }
}
